import { App, ConfigProvider } from 'antd';
import zhCN from 'antd/locale/zh_CN';
import dayjs from "dayjs";
import React from 'react';
import { createRoot } from 'react-dom/client';
import { HashRouter, Navigate, Route, Routes } from 'react-router-dom';
import { theme } from '../config';
import "./app.css";
import Dev from './Dev';
import Home from './Home';
import Login from './Login';
import MpComponent from './MpComponent';
import Page from './Page';
import Session from './Session';

dayjs.locale('zh-cn');

function BaseApp() {
  const LoginComponent = BaseApp.Login ?? Login;
  return (
    <React.StrictMode>
      <ConfigProvider locale={zhCN} theme={theme}>
        <App component={false}>
          <HashRouter>
            <Routes>
              <Route path="" exact element={<Navigate to="mp" />} />
              <Route path=":sys" element={<Session loginComponent={LoginComponent} />}>
                <Route path="" exact element={<Navigate to="home" />} />
                <Route path="home" element={<Home />} />
                <Route path="page/:id" element={<Page />} />
                {window.location.hostname === 'localhost' ? <Route path="dev/:name" element={<Dev />} /> : null}
              </Route>
              <Route path="public/:name" element={<MpComponent />} />
            </Routes>
          </HashRouter>
        </App>
      </ConfigProvider>
    </React.StrictMode>
  );
};

BaseApp.mount = (root) => {
  createRoot(root).render(<BaseApp />);
};

export default BaseApp;